<template>
<div>
   <div class="content page-order"  style="padding-bottom:2.5rem;overflow-x: hidden;">
       <div class="orderQueue">
           <div class="orderTitle">
               <label>历史委托</label>
               <span class="button f-fr" :class="{no_active:is_not_select_all}"  v-on:click=select_all()>显示所有币种</span>
           </div>
           <div v-if="list.length==0" class="noData">
               <img src="/static/app/images/noData.png"/>
               <p>暂无历史委托</p>
           </div>
           <div class="order" v-for="info in list" >
               <div >
                   <span class="symbol">{{info.up_coin_type}} / {{info.up_use_coin_type}}
                       <span v-bind:class="{green:info.is_buy, magenta:info.is_sell }">{{info.order_title}}</span>
                   </span>
                   <div class="time gray">挂单时间 : {{info.create_time}}</div>
                   <div class="time gray">成交时间 : {{info.finish_time}} </div>
               </div>
                   <table style="width: 100%">
                   <tbody>
                       <tr>
                           <th class="f-center">{{info.price}}</th>
                           <th class="f-center">{{info.count}}</th>
                           <th class="f-center">{{info.amount}}</th>
                       </tr>
                      <tr>
                           <td class="f-center gray">成交价格</td>
                           <td class="f-center gray">数量</td>
                       <td class="f-center gray">成交金额</td>
                       </tr>
                   </tbody>
                   </table>
          </div>
       </div>
   </div>
</div>

</template>

<script>

var dict = {
    coin_type : 'btc',
    use_coin_type : 'bitcny'
}
var order_data = {
    list : []
}
export default {
  name: 'HISTORY',
    data: function () {
        // 初始化
        //
        return order_data
    },
    computed: {
    },

    created:function () {{}
        // get all list
        this.is_not_select_all=true
        order_data.coin_type=dict.coin_type
        order_data.use_coin_type=dict.use_coin_type
        order_data.up_coin_type=dict.coin_type.toUpperCase()
        order_data.up_use_coin_type=dict.use_coin_type.toUpperCase()
        this.get_order_history()
    },

    methods:{
        get_order_history:function()
        {
            var params = {coin_type: this.coin_type, use_coin_type: this.use_coin_type}
            if (!this.is_not_select_all)
            {
                params = {}
            }
            //console.log("debug ")
            //console.log(params)
            $.post("/btc/get_order_history", params,
            (data) =>{
                if (data.length == 0)
                    return
                var jsonobj = data
                //jsonobj.reverse()
                //console.log("getorder "  + JSON.stringify(jsonobj))
                var history_list = []
                for (var i=0; i < jsonobj.length; i++)
                {

                    var info = jsonobj[i]
                    var row = {}
                    row.id = info.id
                    row.coin_type = info.coin_type
                    row.use_coin_type = info.use_coin_type
                    row.up_coin_type = row.coin_type.toUpperCase()
                    row.up_use_coin_type = row.use_coin_type.toUpperCase()

                    row.price = info.price
                    row.count = info.count
                    row.amount = info.price * info.count
                    row.create_time = date_format_iso(info.create_time)
                    row.finish_time = date_format_iso(info.finish_time)
                    row.order_type = info.order_type
                    if (info.order_type == 1 || info.order_type == 11)
                    {
                        row.is_buy = true
                        row.is_sell = false
                        row.order_title = info.order_type == 1 ? '限价买入' : '市价买入'
                    }
                    else
                    {
                        row.is_buy = false
                        row.is_sell = true
                        row.order_title = info.order_type == 2 ? '限价卖出' : '市价卖出'
                    }
                    history_list.push(row)
                }

                this.list = history_list
                //var data = {
                    //    coin0: g_coin0,
                    //    coin1: g_coin1,
                    //    coin0_info: g_coin_info[g_coin0],
                    //    coin1_info: g_coin_info[g_coin1],
                    //    jsonobj: jsonobj.reverse(),
                    //}
                });
            },
            select_all:function(){
                if (this.is_not_select_all)
                {
                    this.is_not_select_all=false
                }
                else
                {
                    this.is_not_select_all=true
                }
                this.get_order_history()
            }
        }
    };

</script>

